Overview
Thegdal_baseline_slope.py script calculates specialized slope values from Digital Elevation Models (DEMs) using variable baseline lengths. Unlike standard slope algorithms, this tool measures slope across specific pixel distances, making it particularly useful for rover mission planning where traversability depends on slope over specific ground distances.
This tool was developed for Mars rover mission planning but can be applied to any planetary body with DEM data.
Installation
Requires Anaconda Python environment with GDAL, NumPy, and SciPy:Usage
Parameters
Baseline length in pixels (e.g., 1, 2, 5). If omitted, uses Horn’s method (standard 3x3 slope calculation).
Output data type. Set to
Byte to scale 32-bit floating point slopes to 8-bit using: DN = (Slope * 5) + 0.2. A 32-bit version is still generated as 32bit_outfile.tif.Trim 1-5 pixels from image edges based on selected baseline amount.
Input DEM file (any GDAL-readable format).
Output slope file (GeoTIFF format).
Mathematical Method
The baseline slope algorithm uses a moving window that samples only the corner pixels, measuring slope across a specified baseline distance.Baseline = 2 Example
Uses a 3×3 pixel window, sampling only the 4 corners:Baseline = 5 Example
Uses a 6×6 pixel window, sampling only the 4 corners:baseline = 5.
Horn’s Method (Default)
When no baseline is specified, the script uses Horn’s Method (equivalent togdaldem slope):
For more information on spatial filters, see the ISIS3 Spatial Filters Guide.
Examples
Basic Slope with Baseline = 5
8-bit Output with Cropping
32bit_slope_2m_8bit.tif- Full 32-bit floating point slopes in degreesslope_2m_8bit.tif- 8-bit scaled version (1-255)
HiRISE DEM Processing
8-bit Scaling Formula: The Byte output uses
DN = (Slope * 5) + 0.2, which deliberately maps slopes >50° to DN value 255.Standard Slope (Horn’s Method)
Output Files
| Output Type | Description |
|---|---|
| 32-bit Float | Slope values in degrees (full precision) |
| 8-bit Byte | Scaled slopes: DN = (Slope × 5) + 0.2, offset = -0.2, scale = 0.2 |
| Cropped | Edge pixels removed based on baseline (prevents edge artifacts) |
Rover Mission Applications
Choose Baseline
Select baseline based on rover wheelbase or critical distance:
- Baseline = 1: ~1m for small rovers
- Baseline = 2: ~2m for MER-class rovers
- Baseline = 5: ~5m for larger vehicles or obstacle detection
Apply Thresholds
Use slope output to identify traversable terrain:
- Safe: < 15°
- Caution: 15-25°
- Avoid: > 25° (typical rover limits)
Script Location
Related Tools
The repository includes helper scripts:gdal_hist.py- Generate slope histogramsslope_histogram_cumulative_graph.py- Create cumulative slope distribution graphsgdal_HiRISE_RoverSlope_crop.pl- Batch processing for HiRISE DEMsgdal_CTX_RoverSlope_crop.pl- Batch processing for CTX DEMs
Performance Notes
- Processing speed depends on DEM size and baseline length
- Larger baselines require larger filter windows but process similar times
- Edge pixels are set to NoData when using
mode='constant'
References
- Kirk, R.L., et al. - Baseline slope calculation methodology for rover planning
- USGS Astrogeology GDAL Scripts